//
//  EFengComposeEmotionToolView.m
//  WZEfengAndEtong
//
//  Created by wanzhao on 16/3/7.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "EFengComposeEmotionToolView.h"
#import "UIImage+Extension.h"
#import "MicroDef.h"
#import "UIUtil.h"
#import "EmotionMenueButton.h"

@interface EFengComposeEmotionToolView ()

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, weak) UIButton *rencentButton;
@property (nonatomic, weak) UIButton *sendButton;


@end

@implementation EFengComposeEmotionToolView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupSubViews];
    }
    return self;
}

- (void)setupSubViews
{
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, HARDWARE_SCREEN_WIDTH, 0.5f)];
    line.backgroundColor = RGBCOLOR(212, 212, 212);
    [self addSubview:line];
    
    UIButton *sendButton = [UIButton buttonWithType:UIButtonTypeCustom];
    sendButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
    [sendButton setTitle:@"确定" forState:UIControlStateNormal];
    [sendButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [sendButton setBackgroundColor:RGBACOLORWithAlpha(38, 151, 253, 1.0)];
    [self addSubview:sendButton];
    [sendButton addTarget:self action:@selector(didSend) forControlEvents:UIControlEventTouchUpInside];
    self.sendButton = sendButton;
    
    
    
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.bounces = YES;
    scrollView.scrollEnabled = YES;
    scrollView.alwaysBounceHorizontal = YES;
    scrollView.alwaysBounceVertical = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    [self addSubview:scrollView];
    self.scrollView = scrollView;
    [self setupScrollView];
    
}


- (void)setupScrollView
{
    //    EmotionMenueButton *rencentButton = [self setupButtonWithNorImageName:@"icon-latest" selectImageName:@"icon-latest" higImageName:@"icon-latest" emotionType:@"rencentEmotion"];
    //    //    bug6070
    //
    //    [self.scrollView addSubview:rencentButton];
    //    [rencentButton addTarget:self action:@selector(selectEmotion:) forControlEvents:UIControlEventTouchUpInside];
    //    self.rencentButton = rencentButton;
    //
    //    EmotionMenueButton *defaultButton = [self setupButtonWithNorImageName:@"d_taikaixin" selectImageName:@"d_taikaixin" higImageName:@"d_taikaixin" emotionType:@"defaultEmotion"];
    //    [self.scrollView addSubview:defaultButton];
    //    [defaultButton addTarget:self action:@selector(selectEmotion:) forControlEvents:UIControlEventTouchUpInside];
    
}
- (void)selectEmotion:(EmotionMenueButton *)button
{
    if ([self.eFengComposeEmotionToolViewDelegate respondsToSelector:@selector(EFengComposeEmotionToolViewDidSelectEmotionWithType:)]) {
        [self.eFengComposeEmotionToolViewDelegate EFengComposeEmotionToolViewDidSelectEmotionWithType:button.emotionType];
    }
}

- (void)didSend
{
    if ([self.eFengComposeEmotionToolViewDelegate respondsToSelector:@selector(EFengComposeEmotionToolViewDidSure)]) {
        [self.eFengComposeEmotionToolViewDelegate EFengComposeEmotionToolViewDidSure];
    }
}
- (EmotionMenueButton *)setupButtonWithNorImageName:(NSString *)norImageName selectImageName:(NSString *)selectImageName higImageName:(NSString *)higImageName emotionType:(NSString *)emotionType
{
    EmotionMenueButton *button = [[EmotionMenueButton alloc] init];
    button.emotionType = emotionType;
    [button setImage:[UIImage imageNamed:norImageName] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:selectImageName] forState:UIControlStateSelected];
    [button setImage:[UIImage imageNamed:higImageName] forState:UIControlStateHighlighted];
    
    return button;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.sendButton.frame = CGRectMake(self.frame.size.width - 60, 0, 60, self.frame.size.height);
    self.scrollView.frame = CGRectMake(0, 0, self.frame.size.width - self.sendButton.frame.size.width, self.frame.size.height);
    CGFloat btnW = 50;
    CGFloat btnH = self.frame.size.height;
    CGFloat btnY = 0;
    CGFloat btnX = 0;
    self.scrollView.contentSize = CGSizeMake(btnW * self.scrollView.subviews.count, 0);
    int i = 0;
    for (UIButton *btn in self.scrollView.subviews) {
        btnX = i * btnW;
        btn.frame = CGRectMake(btnX, btnY, btnW, btnH);
        i ++;
    }
}


@end
